package org.tea.crawl.biz.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.tea.crawl.biz.common.ResponseResult;
import org.tea.crawl.biz.domain.dto.CookiePropDto;
import org.tea.crawl.biz.domain.service.CookieService;

import javax.annotation.Resource;

/**
 * 有关 Cookie 的服务控制器
 *
 * @author lxh
 */
@RestController
@CrossOrigin("*")
@RequestMapping(path = "/cookie")
public class CookieServerController {

    private final static Logger log = LoggerFactory.getLogger(CookieServerController.class);

    @Resource(name = "jdCookieService")
    private CookieService jdCookieService;

    @PostMapping(path = "/validJdCookie")
    public ResponseResult<?> validJdCookie() {
        return ResponseResult.success(CookiePropDto.valueOf(
                jdCookieService.createValidSingleCookie()));
    }

    @PostMapping(path = "/releaseJdCookie/{cookieId}")
    public ResponseResult<?> validJdCookie(@PathVariable(name = "cookieId") String cookieId) {
        return ResponseResult.success(jdCookieService.releaseCookie(cookieId));
    }
}
